<template>
	<div class="" style="width: 100%;">
		<head-top></head-top>


	
		<div class="table_container" :style="'width: 90%;  overflow: hidden;  height:1000px;'">
			<div style="margin: 5px; display: flex;">
				<span style="font-size: 20px;width: 100px;">盘后报表 :  </span>
				<div>
					<el-button size="mini" type="success" @click="get_exchange_arrange()">刷新</el-button>
					
				</div>

				<span style="font-size: medium; padding: 10px;">日期:</span>
				<el-select v-model="date_choice" size="small" clearable filterable placeholder="请选择"
					@change="get_exchange_arrange()">
					<el-option v-for="item in date_options" :key="item.label" :label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
				<span style="font-size: medium; padding: 10px;">account:</span>
				<el-select v-model="account_choice" size="small" clearable filterable placeholder="请选择"
					@change="get_exchange_arrange()">
					<el-option v-for="item in account_options" :key="item.label" :label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
				
			</div>

			<el-table ref="singleTable" :data="arrange_data" height="1000px" border size='small' :fit='true'
				:style="'width:'+(screenWidth*1.0)+'px;'" :row-class-name=" tableRowClassNamemoneyout"  @selection-change="handleSelectionChange">
			
		     	<el-table-column  type="index" label="ID"  width="50"></el-table-column>
				<el-table-column prop="date_str" label="日期"  sortable  align></el-table-column>
				<el-table-column prop="account" label="account"  sortable  align></el-table-column>
				<el-table-column prop="server" label="server"  sortable  align></el-table-column>
				<el-table-column prop="product_strategy" label="product_strategy"  sortable  align></el-table-column>
				<el-table-column prop="adjust_pnl" label="adjust_pnl"  sortable  align></el-table-column>
				<el-table-column prop="index_increase" label="指数数据"  sortable  align></el-table-column>
				
				<el-table-column prop="account_increase_per" label="account_increase_per"  sortable  align></el-table-column>
				<el-table-column prop="account_alpha" label="account_alpha"  sortable  align></el-table-column>
				<el-table-column prop="adjust_increase_per" label="adjust_increase_per"  sortable  align></el-table-column>
				<el-table-column prop="adjust_alpha" label="adjust_alpha"  sortable  align></el-table-column>
				<el-table-column prop="check_marketvalue_per" label="check_marketvalue_per"  sortable  align></el-table-column>
				<el-table-column prop="adjust_fee" label="adjust_fee"  sortable  align></el-table-column>
				<!-- <el-table-column prop="hand_gross_pnl" label="hand_gross_pnl"  sortable  align></el-table-column> -->
				<el-table-column prop="output_fee" label="output_fee"  sortable  align></el-table-column>
				<el-table-column prop="output_fee_yukou" label="output_fee_yukou"  sortable  align></el-table-column>
				<!-- <el-table-column prop="loc_target_aum" label="loc_target_aum"  sortable  align></el-table-column> -->
				<!-- <el-table-column prop="loc_target_dianshu" label="loc_target_dianshu"  sortable  align></el-table-column> -->
				<el-table-column prop="account_increase" label="盘后误差"   sortable  align>
					<template slot-scope="scope">
						<span style="color:red ">  {{Math.round( scope.row.account_increase -(scope.row.hand_gross_pnl-scope.row.output_fee_yukou )) }}</span>
					</template>
				</el-table-column> 
				<el-table-column prop="account_increase" label="早盘误差"   sortable  align>
					<template slot-scope="scope">
						<span style="color:red ">  {{Math.round( scope.row.account_increase+scope.row.adjust_fee -(scope.row.hand_gross_pnl-scope.row.output_fee )) }}</span>
					</template>
				</el-table-column> 
				
				<el-table-column label="操作" :width='90'>
					<template slot-scope="scope">
						<el-button size="mini" type="primary" @click="handlefixaccount(scope.$index, scope.row,'binary')">修改
						</el-button>
					</template>
				</el-table-column>
		
			</el-table>

		</div>
		
		
		
		<el-dialog :visible.sync="visible2">
			<div style="display: flex;flex-flow: column; justify-content:center;">
				<div style="display: flex; justify-content:center;">
					<span style="color: orange;font-size: 24px; font-family: KaiTi, Helvetica, sans-serif;">修改账户 {{fix_account['account']}}</span>
				</div>
				<div style="display: flex;flex-flow:row; ">
					<div style="width: 100%; height: 500px;overflow-y: scroll;">
						
						
						
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%; ">date_str：</span>
							<el-input v-model="fix_account['date_str']" size="small" style="width: 20%;"placeholder="date_str" disabled></el-input>
							<span style="width: 20%; padding-left: 5%;">bond_increase：</span>
							<el-input v-model="fix_account['product_strategy']" size="small" style="width: 20%;"placeholder="product_strategy" disabled></el-input>
						</div>
						
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">account_increase_per：</span>
							<el-input v-model="fix_account['account_increase_per']" size="small" style="width: 20%;"placeholder="account_increase_per" ></el-input>
							<span style="width: 20%; padding-left: 5%;">account_alpha：</span>
							<el-input v-model="fix_account['account_alpha']" size="small" style="width: 20%;"placeholder="account_alpha"></el-input>
							
						</div>
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">adjust_increase_per：</span>
							<el-input v-model="fix_account['adjust_increase_per']" size="small" style="width: 20%;"placeholder="product_strategy" ></el-input>
							<span style="width: 20%; padding-left: 5%;">adjust_alpha：</span>
							<el-input v-model="fix_account['adjust_alpha']" size="small" style="width: 20%;"placeholder="adjust_alpha"></el-input>
							
						</div>
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">index_increase：</span>
							<el-input v-model="fix_account['index_increase']" size="small" style="width: 20%;"placeholder="index_increase" disabled></el-input>
							<span style="width: 20%; padding-left: 5%;">cash_transfer：</span>
							<el-input v-model="fix_account['cash_transfer']" size="small" style="width: 20%;"placeholder="cash_transfer" disabled ></el-input>
							
						</div>
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">account_increase：</span>
							<el-input v-model="fix_account['account_increase']" size="small" style="width: 20%;"placeholder="account_increase" disabled></el-input>
							<span style="width: 20%; padding-left: 5%;">adjust_fee：</span>
							<el-input v-model="fix_account['adjust_fee']" size="small" style="width: 20%;"placeholder="adjust_fee" disabled></el-input>
						</div>
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">hand_gross_pnl：</span>
							<el-input v-model="fix_account['hand_gross_pnl']" size="small" style="width: 20%;"placeholder="hand_gross_pnl" disabled></el-input>
							<span style="width: 20%; padding-left: 5%;">hand_net_pnl：</span>
							<el-input v-model="fix_account['hand_net_pnl']" size="small" style="width: 20%;"placeholder="hand_net_pnl" disabled></el-input>
						</div>
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">output_fee_yukou：</span>
							<el-input v-model="fix_account['output_fee_yukou']" size="small" style="width: 20%;"placeholder="output_fee_yukou" disabled></el-input>
							<span style="width: 20%; padding-left: 5%;">output_fee：</span>
							<el-input v-model="fix_account['output_fee']" size="small" style="width: 20%;"placeholder="output_fee" disabled></el-input>
						</div>
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">account_sod_stock_asset：</span>
							<el-input v-model="fix_account['account_sod_stock_asset']" size="small" style="width: 20%;"placeholder="account_sod_stock_asset" disabled></el-input>
							<span style="width: 20%; padding-left: 5%;">account_eod_stock_asset：</span>
							<el-input v-model="fix_account['account_eod_stock_asset']" size="small" style="width: 20%;"placeholder="account_eod_stock_asset" disabled></el-input>
						</div>
						
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">account_sod_total_asset：</span>
							<el-input v-model="fix_account['account_sod_total_asset']" size="small" style="width: 20%;"placeholder="account_sod_total_asset" disabled></el-input>
							<span style="width: 20%; padding-left: 5%;">account_eod_total_asset：</span>
							<el-input v-model="fix_account['account_eod_total_asset']" size="small" style="width: 20%;"placeholder="account_eod_total_asset" disabled></el-input>
						</div>
						
						
						
						
						
					</div>
					
				</div>
				<div style="display: flex;align-items: center;padding-top: 2px;  justify-content:center">
					<el-button style=" height: 33px;" size="small" type="success" @click="changedata_account()">修改确认</el-button>
				</div>
		
		  
			</div>
		
		
		</el-dialog>
	</div>
</template>

<script>
	import headTop from '@/components/headTop'
	export default {
		data() {
			return {
				in_use_flag:true,
				checkflag: false,
				core_pos: [],
				pos_index_item: '',
				account_choice: "",
				account_options: [],
				target_pos_index_options: [],
				date_choice: "",
				
				date_choice_end: "",
				date_choice_begin: "",
				date_options: [],
				tableData: [],
				currentRow: null,
				inoutflag:false,
				count: 0,
				exchange_detail: [],
				LP_account_list: [],
				fix_account: {},
				visible: false,
				visible2: false,
				screenWidth: document.body.clientWidth, // 屏幕尺寸
				screenHeight: document.body.clientHeight, // 屏幕尺寸
				moneyindex: "0",
				arrange_data: [],
				arrange_data1: [],
				strategy_total_asset:0,
				
			
				
			
				
				use_options: [
					{
						value: 'yes',
						label: 'yes'
					},
					{
						value: 'no',
						label: 'no'
					},

				],

			}
		},
		components: {
			headTop,
		},



		activated() {

			// console.log("当前登入用户", this.$store.state.adminInfo.name);
			//    if (this.tradesysPermission_list.indexOf (this.$store.state.adminInfo.permission) ==-1) {
			// 	console.log(this.$store.state.adminInfo.name,"未登入")
			// 	this.$message({type: 'error',	message: '没有权限',});
			// 	this.$router.push({
			// 		path: `/manage`
			// 	})
			// }
		},
		created() {
			
			this.get_exchange_arrange()
			this.get_date_last()
			this.get_account_list()
		},
		computed: {
			
		},

		methods: {
			
			handleSelectionChange(val) {
				this.multipleSelection = val;
				let total_asset=0;
				for(let i=0;i<this.multipleSelection.length;i++){
					// console.log(this.multipleSelection[i].total_asset) 	
					total_asset+= this.multipleSelection[i].total_asset
				}
				this.strategy_total_asset=total_asset
				// console.log(total_asset)
							
			},
			add_fix(){
			    this.fix_account['product_total_increase_per'] = 
			    parseFloat(this.fix_account['bond_increase_per'] || 0) +
			    parseFloat(this.fix_account['commodity_increase_per'] || 0) +
			    parseFloat(this.fix_account['stock_increase_per'] || 0) +
			    parseFloat(this.fix_account['future_increase_per'] || 0) +
			    parseFloat(this.fix_account['cffex_increase_per'] || 0);
				// this.fix_account['product_total_increase']=this.fix_account['bond_increase']+this.fix_account['commodity_increase']
				// +this.fix_account['stock_increase']+this.fix_account['future_increase']+this.fix_account['cffex_increase']
				this.fix_account['product_total_increase_per']=this.fix_account['product_total_increase_per'].toFixed(3);
				// this.fix_account['product_total_increase']=this.fix_account['product_total_increase'].toFixed(2);
			},
			handlefixaccount(index, row) {
				console.log("row", row)
				this.fix_account = row
				this.visible2 = true
			},
			get_date_last() {
				var that = this;
				
				
				let sql =
					" select distinct date_format(date,'%Y-%m-%d') as date_str  from `LP_account_day` where date>'20250101' order by date_str desc;"
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {
					console.log(response, 'data_tradesys_account');
					if (response.status = 200) {
						that.date_options = []
						that.date_choice=response.data[0]['date_str']
						//for (var i = 0; i < response.data.length; i++) {
						for (var i =0; i <=response.data.length; i++) {
							let char = {
								value: response.data[i]['date_str'],
								label: response.data[i]['date_str'],
							};
							that.date_options.push(char);
						}
					} else {
						console.log(response.data.statusCode);
					}
				})
			
			},
		
			get_account_list() {
				var that = this;
				
				
				let sql =
					" select distinct account  from `config_account`  where use_flag='yes' and account_type in ('equities','future_commodity','future_cffex')"
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {
					console.log(response, 'data_tradesys_account');
					if (response.status = 200) {
						that.account_options = []
						//for (var i = 0; i < response.data.length; i++) {
						for (var i =0; i <=response.data.length; i++) {
							let char = {
								value: response.data[i]['account'],
								label: response.data[i]['account'],
							};
							that.account_options.push(char);
						}
					} else {
						console.log(response.data.statusCode);
					}
				})
			
			},
		
		
		
		
		
		
		
		
		
		
			get_exchange_arrange() {
				var that = this;
				console.log(that.lpapi2)
				let sql = " select * ,date_format(date,'%Y-%m-%d') as date_str  from LP_account_day	where date  =  CURDATE() order by product_strategy;"
				if (this.date_choice != "") {
					 sql = "select * ,date_format(date,'%Y-%m-%d') as date_str  from LP_account_day	where date  ='"+this.date_choice+"' order by product_strategy;"
				} 
				if ( this.account_choice != "") {
					sql = "select * ,date_format(date,'%Y-%m-%d') as date_str  from LP_account_day	where date >='"+this.date_choice+"' \
					and account =  '"+this.account_choice+"'  order by product_strategy;"
					 ;
					
			   }
				that.arrange_data = []
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {

					console.log(response.data[0], 'LP_account_day')

					if (response.status = 200) {
						if (response.data[0].hasOwnProperty('message')) {
							that.arrange_data = []
						} else {
							that.arrange_data = response.data;
							
						}
						// that.arrange_data = response.data;
					} else {
						console.log(response.data.statusCode);
					}
				})


			},


			changedata_account(){
				var that = this
				if (this.allow_readpw!='yes' ){
					this.$prompt('请输入密码', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',inputType: 'password',
						inputType: 'password',
					}).then(({
						value
					}) => {
						if (value == '621890') {
							this.$message({
								type: 'success',
								message: '密码正确:'
							});
							that.allow_readpw='yes'
						} else {
							this.$message({
								type: 'error',
								message: '密码出错'
							});
						}
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '取消输入'
						});
					});
					return
				}
				
				that.$confirm('此操作将永久修改数据, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',inputType: 'password',
					type: 'warning'
				}).then(() => {
					let fixdata=that.fix_account
			
				
					
					let sql3 = "UPDATE `LP_account_day` SET `adjust_increase_per` = '" + fixdata['adjust_increase_per'] + "', \
						`adjust_alpha` = '" + fixdata['adjust_alpha'] + "' \
						WHERE `account` = '" + fixdata['account'] + "' and date='" + fixdata['date_str'] + "' ;"
					
					// var jsonStr = JSON.stringify(fixdata);
					that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql3).then(response => {
					// that.$axios.post(that.lpapi2, "form=do_sql&table=LP_account_list&updata="+ jsonStr).then(response => {
						if (response.status = 200) {
							that.$message({
								type: 'success',
								message: '修改成功!',
							});
							that.visible2 = false;
							that.get_exchange_arrange();
							that.$forceUpdate();
						} else {
							that.visible2 = false;
							that.$message({
								showClose: true,
								message: response.data,
								duration: 4000,
								type: 'error'
							});
						}
					})
				
				}).catch(() => {
					that.$message({
						type: 'info',
						message: '已取消修改'
					});
				});
				
				
				
				
			},

		
			
			tableRowClassNamemoneyout({
				row,
				rowIndex
			}) {
		
				if (this.arrange_data[rowIndex]['status'] == '待处理' | this.arrange_data[rowIndex]['status'] == '准备' ) {
					return 'bacorange';
				}
				if (this.arrange_data[rowIndex]['status'] == '异常') {
					return 'bacOrangeRed';
				}
				return '';
			}

		},
	}
</script>

<style>
	.el-table .bacOrangeRed {
		background: OrangeRed;
	}

	.el-table .bacorange {
		background: orange;
	}

	.el-table .success-row {
		background: grey;
		color: white;
	}

	.table_container {
		margin: 20px 5%;
		/* background-color: #0000FF; */
	}

	.el-table .grey {
		background: Silver;
	}

	.el-table .DarkGray {
		background: DarkGray;
	}

	.el-table .LightCoral {
		background: LightCoral;
		color: white;
	}

	.el-table .LimeGreen {
		background: LimeGreen;
	}

	.el-table .green {
		background: green;
	}

	.el-table .LightSlateGray {
		background: LightSlateGray;
	}

	.el-table .red {
		background: red;
		color: white;
	}

	.el-table .orange {
		background: NavajoWhite;
		color: black;
	}

	.el-table .blue {
		background: blue;
	}

	.el-table .purple {
		background: Violet;
		color: black;
	}

	.el-table .LightSteelBlue {
		background: LightSteelBlue;
	}

	.el-table .Goldenrod {
		background: Goldenrod;
	}

	.el-table .xingmu {
		background: Goldenrod;
		color: red;
		font-weight: bold;

	}


	.el-table .black {
		background: black;
		color: white;
	}

	.el-table .green {
		background: green;
		color: white;
	}

	.el-table .CornflowerBlue {
		background: CornflowerBlue;
		color: white;
	}

	.el-table .DodgerBlue {
		background: DodgerBlue;
	}
</style>
